package main

import (
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
	"gitee.com/huanminabc/go-utils/file"
	log "github.com/sirupsen/logrus"
	_ "go-CodeToolUi/components/config"
	"go-CodeToolUi/core"
	"go-CodeToolUi/framework"
	"go-CodeToolUi/inner_resources/_icon_"
	"os"
	"time"
)

func init() {
	//初始化日志
	file.InitLog(file.GetUserHomeDir()+string(os.PathSeparator)+"log", "log", 1024*1024*100, time.Hour*24*7)
	// 设置日志级别为Info
	log.SetLevel(log.InfoLevel)
	//配置字体不然乱码
	core.AppCore.Settings().SetTheme(&MyTheme{})

}

func main() {

	lock := file.FileLock("go-CodeToolUi.lock", func() {
		//应用配置
		framework.CombinationFramework()
	})
	if !lock {
		repeatOpen()
		return
	}
}

// 重复打开
func repeatOpen() {
	a := app.New()
	a.Settings().SetTheme(&MyTheme{})
	w := a.NewWindow("错误")
	w.SetFixedSize(true)
	w.CenterOnScreen()
	w.SetIcon(_icon_.ResourceIconPng)
	hello := widget.NewLabel("请不要重复打开程序")
	w.SetContent(container.NewVBox(
		hello,
		widget.NewButton("确认", func() {
			w.Close()
			a.Quit() //退出程序
		}),
	))
	w.SetOnClosed(func() {
		w.Close()
		a.Quit()
	})
	w.ShowAndRun()

}
